/**
PDTC
Copyright 2011 Patrick Devaney

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <iostream>
#include <string.h>
using namespace std;
/*
Fahrenheit notes:
5/9 = ?
9/5 = 1.8
Celsius -> Kelvin
173.15
*/

// Celsius to Kelvin
int ctok() {
long double temp;
cout << "What's the temperature in Celsius?" << endl;
cin >> temp;
// Celsius -> Kelvin
temp = temp + 273.15;
// Check that we're not defying the laws of physics,
// as I'll take no part in any of that.
if(temp < 0) {
cout << "It's not physically possible for the temperature to be that low, sorry.";
}
// If not, give the person their temperature.
else {
cout << endl << "The temperature in Kelvin is: " << temp << endl;
}
}
// Fahrenheit to Kelvin
int ftok() {
long double temp;
cout << "What's the temperature in Fahrenheit?" << endl;
cin >> temp;
// Fahrenheit -> Celsius
temp = temp - 32;
temp = temp * 5/9;
// Celsius -> Kelvin
temp = temp + 273.15;
// Again, no defying physics
if(temp < 0) {
cout << "It's not physically possible for the temperature to be that low, sorry.";
}
else {
cout << "The temperature in Kelvin is: " << temp << endl;
}
}
// Kelvin to Celsius
int ktoc() {
long double temp;
cout << "What's the temperature in Kelvin?" << endl;
cin >> temp;
// Still no defying physics
if(temp < 0) {
cout << "It's not physically possible for the temperature to be that low, sorry.";
}
else {
// Kelvin -> Celsius
temp = temp - 273.15;
cout << "The temperature in Celsius is: " << temp << endl;
}
}
// Kelvin to Fahrenheit
int ktof() {
long double temp;
cout << "What's the temperature in Kelvin?" << endl;
cin >> temp;
// No defying physics
if(temp < 0) {
cout << "It's not physically possible for the temperature to be that low, sorry.";
}
else {
// Kelvin -> Celsius
temp = temp - 273.15;
// Celsius -> Fahrenheit
temp = temp * 9/5;
temp = temp + 32;
cout << "The temperature in Fahrenheit is: " << temp << endl;
}
}
// Fahrenheit to Celsius
int ftoc() {
long double temp;
cout << "What's the temperature in Fahrenheit?" << endl;
cin >> temp;
// Fahrenheit -> Celsius
temp = temp - 32;
temp = temp * 5/9;
// Really, no physics defiance on my watch
if(temp + 273.15 < 0) {
cout << "It's not physically possible for the temperature to be that low, sorry.";
}
else {
cout << "The temperature in Celsius is: " << temp << endl;
}
}
// Celsius to Fahrenheit
int ctof() {
long double temp;
cout << "What's the temperature in Celsius?" << endl;
cin >> temp;
// If it's not obvious by now, NO VIOLATING PHYSICS!
if(temp + 273.15 < 0) {
cout << "It's not physically possible for the temperature to be that low, sorry.";
}
else {
// Celsius -> Fahrenheit
temp = temp * 9/5;
temp = temp + 32;
cout << "The temperature in Fahrenheit is: " << temp << endl;
}
}